<template>
  <div class="travel-announcement">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>旅行公告</span>
          <div class="header-actions">
            <el-input
              v-model="queryForm.title"
              placeholder="搜索公告标题"
              prefix-icon="Search"
              style="width: 240px;"
            />
            <el-button type="primary" @click="getList">搜索</el-button>
          </div>
        </div>
      </template>
      
      <!-- 公告列表 -->
      <div class="announcement-list">
        <div class="announcement-item" v-for="(announcement, index) in announcements" :key="index">
          <div class="announcement-header">
            <div class="announcement-title-wrapper">
              <h3 class="announcement-title">
                <router-link :to="'/front/travel-announcement/' + announcement.id">{{ announcement.title }}</router-link>
              </h3>
              <el-tag v-if="announcement.isFirst==1" type="warning">置顶</el-tag>
            </div>
            <div class="announcement-meta">
              <span class="publish-time">{{ announcement.createTime }}</span>
              <span class="publisher">发布人：{{ announcement.createUser }}</span>
              <span class="view-count">浏览：{{ announcement.viewCount }}</span>
            </div>
          </div>
          <div class="announcement-content">
            {{ announcement.summary }}
          </div>
          <div class="announcement-footer">
            <router-link :to="'/front/travel-announcement/' + announcement.id" class="view-detail">查看详情</router-link>
          </div>
        </div>
      </div>
      
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="queryForm.pageNum"
          v-model:page-size="queryForm.pageSize"
          :page-sizes="[10, 20, 50]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { noticeList } from '@/request/notice'



const queryForm = reactive({
  pageNum: 1,
  pageSize: 1000,
  title: ''
})

const total = ref(0)
const announcements = ref([])

const getList = ()=>{
  noticeList({
    pageNum: queryForm.pageNum,
    pageSize: queryForm.pageSize,
    title: queryForm.title
  }).then(res=>{
    announcements.value = res.records
    total.value = res.total
  }).catch(err=>{
    console.log(err)
  })
}

getList();


// 处理页码变化
const handleCurrentChange = (current) => {
  currentPage.value = queryForm.pageNum = current
  // 实际应用中这里应该调用API获取对应页码的数据
}

// 处理每页显示条数变化
const handleSizeChange = (size) => {
  queryForm.pageSize = size
  queryForm.pageNum = 1
  getList()
}

</script>

<style scoped>
.travel-announcement {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.announcement-list {
  margin-top: 20px;
}

.announcement-item {
  border-bottom: 1px solid #f0f0f0;
  padding: 20px 0;
}

.announcement-item:last-child {
  border-bottom: none;
}

.announcement-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.announcement-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.announcement-title {
  margin: 0;
  font-size: 18px;
}

.announcement-title a {
  color: #333;
  text-decoration: none;
}

.announcement-title a:hover {
  color: #1890ff;
}

.announcement-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  font-size: 14px;
  color: #999;
}

.announcement-content {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.announcement-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.view-detail {
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
}

.view-detail:hover {
  text-decoration: underline;
}

.travel-info {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 14px;
  color: #666;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}
</style>